<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        const person = {
            name: "jack",
            age: 24,
            language: ['java', 'js', 'css']
        }

        console.log(Object.keys(person)); // ["name","age","language"]
        console.log(Object.values(person));// ["jack",24, Array(3)]
        console.log(Object.entries(person));// [Array(2), Array(2), Array(2)]

        //{a:1,b:2,c:3}
        const target = { a: 1 };
        const source1 = { b: 1 };
        const source2 = { c: 1 };
        console.log(target);

        Object.assign(target, source1, source2);
        console.log(target); //{a: 1, b: 1, c: 1}

        // 声明对象简写
        const age = 23;
        const name = "王二";
        const person1 = { age: age, name: name }

        const person2 = { age, name }
        console.log(person2);

        // 对象的函数简写
        let person3 = {
            name: "jack",
            // 以前
            eat: function (food) {
                console.log(this.name + "在吃" + food);
            },
            // 箭头函数this不能使用，要使用 对象.属性
            eat2: food => console.log(person3.name + "在吃" + food),
            eat3(food) {
                console.log(this.name + "在吃" + food)
            }
        }

        person3.eat("香蕉");
        person3.eat2("苹果");
        person3.eat3("橘子");

        // 对象拓展运算符
        //1、拷贝对象（深拷贝）
        let p1 = { name: "any", age: 13 }
        let s = { ...p1 }
        console.log(p1);

        //2、合并对象
        let age1 = { age: 15 }
        let name1 = { name: "any" }
        let p2 = { name1: "张三" }
        p2 = { ...age1, ...name1 }
        console.log(p2);

    </script>
</body>

</html>